@isTest
private class BudgetProductFillControllerTest {

    static testMethod void testMethod1() {
        
    	// 新建 产品
    	Product__c p1= TestUtils.createProduct();
    	p1.Category1__c = '生化';
         p1.BudgetaryProducts__c  ='迈克生化试剂';
    	p1.NCCode__c = '000001';
    	insert p1;

    	Product__c p2= TestUtils.createProduct();
    	p2.Category1__c = '生化';
        p2.BudgetaryProducts__c  ='迈克生化试剂';
    	p2.NCCode__c = '000002';
    	insert p2;
        Product__c p3= TestUtils.createProduct();
        p3.Category1__c = '生化';
        p3.BudgetaryProducts__c  ='迈克生化试剂';
        p3.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('NCProduct', 'Product__c');
        p3.NCCode__c = '110003';
        insert p3;


        Price__c p = new Price__c();
        p.Product__c = p3.Id;
        p.Company__c = '迈克生物股份有限公司';
        p.InstCost__c = 1 ;
        insert p; 


        Id tType  = Utils.getRecordTypeIdByDevNameAndObjName('BudgetTarget', 'SalesBudgetTable__c');
        Id bType  = Utils.getRecordTypeIdByDevNameAndObjName('BudgetBreakdown', 'SalesBudgetTable__c');

        //新建 目标主表
        SalesBudgetTable__c t_st = new SalesBudgetTable__c();

        //t_st.Province__c = '四川省';
        t_st.ProductLine__c = '生化';
        t_st.Year__c = (System.now().year()+1)+'';
        t_st.CompanyName__c = 'MKSW';
        t_st.RecordTypeId = tType;
        insert t_st;
        SalesBudgetTableDetail__c t_sd=  new SalesBudgetTableDetail__c();
        t_sd.Company__c = 'MKSW';
        t_sd.Province__c = '四川省';
        t_sd.ProductLine__c = '生化';
        t_sd.SalesBudgetTable__c = t_st.Id ;
        t_sd.Year__c = (System.now().year()+1)+'';
        t_sd.TZR__c = UserInfo.getUserName();
        insert t_sd;




    	//新建 主表
    	SalesBudgetTable__c st = new SalesBudgetTable__c();
        st.RecordTypeId = bType;
    	st.Province__c = '四川省';
    	st.ProductLine__c = '迈克生化试剂';
    	st.Year__c = (System.now().year()+1)+'';
    	st.CompanyName__c = 'MKSW';

    	insert st;
        SalesBudgetTable__c st1 = new SalesBudgetTable__c();
        st1.RecordTypeId = bType;
        st1.Province__c = '四川省';
        st1.ProductLine__c = '免疫';
        st1.Year__c = (System.now().year()+1)+'';
        st1.CompanyName__c = 'MKSW';
        insert st1;


    	//新建明细表
    	SalesBudgetTableDetail__c sd=  new SalesBudgetTableDetail__c();
    	sd.Province__c = '四川省';
    	sd.ProductLine__c = '生化';
    	sd.Year__c =  (System.now().year()+1)+'';
    	sd.Company__c = 'MKSW';
    	sd.NCCode__c = '000001';
        sd.SalesBudgetTable__c = st.Id;
    	sd.TZR__c = UserInfo.getUserName();
    	insert sd;

    	BudgetProductFillController bpc = new BudgetProductFillController();
    	bpc.selectId = st.Id;

    	bpc.init();

    	bpc.getDetails();


    	bpc.saveJson = bpc.dataJson;
    	System.debug(EncodingUtil.urlDecode(bpc.saveJson,'UTF-8'));
    	bpc.save();

    	Map<String,String>searchMap = new Map<String,String>();
    	searchMap.put('NCCode__c','000002');
		bpc.searchJson = EncodingUtil.urlEncode(JSON.serialize(searchMap),'UTF-8');
    	bpc.getProduct();
        System.debug((System.now().year()+1)+'');
        System.debug([select Id,Year__c,ProductLine__c,CompanyName__c,Province__c,Status__c ,(select Id from SalesBudgetTablejbyu__r ) from SalesBudgetTable__c 
        where RecordType.DeveloperName = 'BudgetBreakdown' ]);

         bpc.getUndetails();

    	bpc.setNil();

        Map<String,String> pm =new Map<String,String>();
        pm.put('INVCODE', '000002');
        pm.put('ACCOUNTTYPE', '三方');
        pm.put('Q1_NMNY', '1');
        pm.put('Q1_NNUMBER', '1');

        List<Object> pL = new List<Object>();
        BudgetProductFillController.importData(EncodingUtil.urlEncode(JSON.serialize(pL), 'UTF-8'), st1.Id);




    }
}